<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/5/27 0027
 * Time: 下午 1:43
 */
namespace app\model;
class ActivityCompany extends  \think\Model{
    public $table="activity_company";

    /**
     * 根据活动ID,返回对应的参加 企业列表
     * @param $activity_id
     * @return mixed
     */
    function get_join_comapny_list_by_activity_id($activity_id){
        $o=$this->where(['activity_id'=>$activity_id])->select();
        $arrs=object2array($o);
        $UserCompany=new \app\model\UserCompany();
        foreach($arrs as $k=>$v){
            $company_info=$UserCompany->get_user_company_by_id($v['user_company_id']);
            $arrs[$k]['company_info']=$company_info;
        }
        return $arrs;
    }

    /**
     * 添加一条用户参加指定招聘活动记录
     * @param $activity_id
     * @param $user_company_id
     * @return int|string
     */
    function add_join_activity_log($activity_id,$user_company_id){
        return $this->insert(['activity_id'=>$activity_id,'user_company_id'=>$user_company_id,'created_at'=>cur_time()],false,true);
    }

    /**
     * 公司是否参加 指定 的招聘活动
     * @param $activity_id
     * @param $user_company_id
     * @return bool
     */
    function if_join_activity($activity_id,$user_company_id){
        $o=$this->where(['activity_id'=>$activity_id,'user_company_id'=>$user_company_id])->column("id");
        if($o[0]){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 返回已经参加指定活动的企业数
     * @param $activity_id
     * @return int|string
     */
    function get_ac_join_company_num($activity_id){
        return $this->where(['activity_id'=>$activity_id])->count();
    }
}